﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 任务状态
{
    public class DrawDataPic
    {
        private int Width;
        private int Height;
        private Panel panel1;
        
        public DrawDataPic(Panel panel)
        {
            this.Width = panel.Width;
            this.Height = panel.Height;
            this.panel1 = panel;
        }

        public void DrawPic(float d1, float d2,Color bcolor,Color fcolor, ref Bitmap bitmap1)
        {
            using (Graphics g = Graphics.FromImage(bitmap1))
            {
                g.Clear(bcolor);
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                Font font1 = new Font("Arial", 38, FontStyle.Bold);
                g.DrawString(d2.ToString(".00"), font1, new SolidBrush(fcolor), new PointF(-10, 52));
                Font font = new Font("Arial", 30, FontStyle.Bold);
                g.DrawString(d1.ToString(".00"), font, new SolidBrush(fcolor), new PointF(-10, 0));
            }
        }
        public void DrawPic(float d1, float d2,float expect,float profit, Color[] color, ref Bitmap bitmap1)
        {
            Color bcolor = color[2];
            Color fcolor = color[0];
            if (d2 < 0)
            {
                bcolor = color[3];
                fcolor = color[1];
            }
            using (Graphics g = Graphics.FromImage(bitmap1))
            {
                g.Clear(bcolor);
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                Font font1 = new Font("Arial", 38, FontStyle.Bold);
                g.DrawString(d2.ToString(".00"), font1, new SolidBrush(fcolor), new PointF(-10, 52));
                Font font = new Font("Arial", 30, FontStyle.Bold);
                g.DrawString(d1.ToString(".00"), font, new SolidBrush(fcolor), new PointF(-10, 0));
                if (expect > 0)
                {
                    int barWidth = (int)((Math.Abs(profit) / expect * 10) * bitmap1.Width);
                    Rectangle barRect;
                    if (profit >= 0)
                    {
                        barRect = new Rectangle(0, bitmap1.Height / 2 - 3, barWidth, 6);
                        g.FillRectangle(new SolidBrush(color[0]), barRect);
                    }
                    else
                    {
                        barRect = new Rectangle(bitmap1.Width - barWidth, bitmap1.Height / 2 - 3, barWidth, 6);
                        g.FillRectangle(new SolidBrush(color[1]), barRect);
                    }
                }
            }
        }
    }

}

